home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / logiso.000 / logiso / Utils / follow_link < prev    next >
Encoding:
Korn shell script  |  1995-03-24  |  796 b   |  37 lines

  1. #! /bin/ksh
  2. USAGE='USAGE: follow_link FILE_PATH
  3.    If FILE_PATH is not a link, echo path, else, echo a path (relative or
  4.    absolute) to the ultimate destination of the link).
  5. '
  6. # (C) Copyright 1995 by Michael Coulter.  All rights reserved.
  7.  
  8. # Process parameters
  9.  
  10.    if [ $# -ne 1 ]
  11.    then
  12.       echo "$USAGE" >&2
  13.       exit 1
  14.    fi
  15.    FILE_PATH="$1"; shift
  16.  
  17. # Do it
  18.  
  19.    if [ ! -L "$FILE_PATH" ]
  20.    then
  21.       echo "$FILE_PATH"
  22.       exit 0
  23.    fi
  24.    LINK="$FILE_PATH"
  25.    while [ -L "$LINK" ]
  26.    do
  27.       NEW_LINK="$(ls -l "$LINK" | cut -c56-500 | sed -e 's/^.* //')"
  28.       if [ "$NEW_LINK" = "${NEW_LINK#/}" ]
  29.       then
  30.      # NEW_LINK is relative, add dirname of FILE_PATH
  31.      DIR_PATH="$(dirname "$LINK")"
  32.      NEW_LINK="$DIR_PATH/${NEW_LINK}"
  33.       fi
  34.       LINK="$NEW_LINK"
  35.    done
  36.    echo "$LINK"
  37.